package com.zzyl.service.impl;

import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    //根据房间id查询床位
    @Override
    public List<BedVo> getBedsByRoomId(Integer roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    //新增床位
    @Override
    public void createBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto,bed);
        bed.setBedStatus(0);//床位状态 0为未入住
        bed.setCreateBy(1L);//创建人
        bed.setCreateTime(LocalDateTime.now());//创建时间
        bed.setUpdateTime(LocalDateTime.now());//更新时间
        bedMapper.createBed(bed);
    }

    //删除床位(根据床位ID)
    @Override
    public void deleteBed(Integer id) {
        bedMapper.deleteBed(id);
    }
    //修改床位
    @Override
    public void updateBed(BedDto bedDto) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(bedDto,bed);
        bed.setCreateBy(1L);//修改人
        bed.setUpdateTime(LocalDateTime.now());//修改时间
        bedMapper.updateBed(bed);
    }

    //根据id查询床位
    @Override
    public BedVo getById(Integer id) {
        Bed bed = new Bed();
        BeanUtils.copyProperties(id,bed);
        return bedMapper.getById(id);
    }
}

